package com.maykk.stu_manager.views;

import com.maykk.stu_manager.global.Student;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @ClassName: StuPage
 * @Description: TODO 视图层
 * @Author: MaykkStar@163.com
 */
public class StuPage {
    /**
     * 欢迎页面
     *
     * @return 功能选择
     */
    public static int welcome() {
        System.out.println("====================");
        System.out.println("= 欢迎使用学生管理系统 =");
        System.out.println("====================");
        System.out.println("=  1 - 查询学员功能  =");
        System.out.println("=  2 - 添加学员功能  =");
        System.out.println("=  3 - 修改学员功能  =");
        System.out.println("=  4 - 删除学员功能  =");
        System.out.println("=  5 -   退出系统   =");
        System.out.println("====================");
        int a;
        do {
            System.out.print("请输入要选择的功能：");
            a = new Scanner(System.in).nextInt();
        } while (a > 5 || a < 0);
        return a;
    }

    /**
     * 显示查询页面
     *
     * @return 功能选择
     */
    public static int SelPage() {
        System.out.println("==================");
        System.out.println("=  1 - 查询全部   =");
        System.out.println("=  2 - 按学号查询   =");
        System.out.println("=  3 - 按姓名查询   =");
        System.out.println("=  4 - 按性别查询   =");
        System.out.println("=  5 - 按年龄查询   =");
        System.out.println("=  6 - 按成绩查询   =");
        System.out.println("=  7 - 按班级查询   =");
        System.out.println("==================");
        int a;
        do {
            System.out.println("请输入要选择的功能:");
            a = new Scanner(System.in).nextInt();
        } while (a > 8 || a < 0);
        return a;
    }

    /**
     * 显示查询到的结果
     *
     * @param stuList 查询结果
     */
    public static void showOutCome(ArrayList<Student> stuList) {
        // 判断集合是否为空
        if (stuList.isEmpty()) {
            System.out.println("未查询到结果！~");
        } else {
            System.out.printf("┌──────┬────────────┬──────┬──────┬──────┬────────────┬──────────┐\n");
            System.out.printf("│%-6s│%-12s│%-6s│%-6s│%-6s│%-12s│%-10s│\n", "ID", "NAME", "SEX", "AGE", "SCORE", "TEL", "CLASSID");
            for (Student stu : stuList) {
                System.out.printf("├──────┼────────────┼──────┼──────┼──────┼────────────┼──────────┤\n");
                System.out.printf("│%-6s│%-11s│%-5s│%-6s│%-6s│%-12s│%-10s│\n", stu.getId(), stu.getName(), stu.getSex(), stu.getAge(), stu.getScore(), stu.getTel(), stu.getClassid());
            }
            System.out.printf("└──────┴────────────┴──────┴──────┴──────┴────────────┴──────────┘\n");
        }
    }

    /**
     * 输入学号
     *
     * @return 用户输入的学号
     */
    public static int inputId() {
        System.out.print("请输入学号：");
        return new Scanner(System.in).nextInt();
    }

    /**
     * 输入姓名
     *
     * @return 用户输入的姓名
     */
    public static String inputName() {
        System.out.println("请输入姓名：");
        return new Scanner(System.in).nextLine();
    }

    /**
     * 输入性别
     *
     * @return 用户输入的性别
     */
    public static int inputSex() {
        int Sex;
        System.out.println("请输入性别：");
        System.out.println("0.女  1.男");
        do {
            Sex = new Scanner(System.in).nextInt();
            if (Sex != 0 && Sex != 1) {
                System.out.println("输入错误，请重新输入！~");
                System.out.println("0.女  1.男");
            }
        } while (Sex != 0 && Sex != 1);
        return Sex;
    }

    public static int inputAge() {
        System.out.println("请输入年龄：");
        return new Scanner(System.in).nextInt();
    }

    /**
     * 输入成绩
     *
     * @return 用户输入的成绩
     */
    public static int inputScore() {
        System.out.println("请输入成绩:");
        return new Scanner(System.in).nextInt();
    }

    /**
     * 输入班级
     *
     * @return 用户输入的班级
     */
    public static String inputClass() {
        System.out.println("请输入班级：");
        return new Scanner(System.in).nextLine();
    }

    public static Student addStu() {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入学生学号（必填）:");
        int id = sc.nextInt();

        System.out.print("请输入学生姓名（必填）:");
        String name = sc.next();

        // System.out.print("请输入学生性别");
        // System.out.print("(0.女  1.男):");
        String sex = String.valueOf(inputSex());

        System.out.print("请输入学生年龄:");
        int age = sc.nextInt();

        System.out.print("请输入学生成绩:");
        float score = sc.nextFloat();

        System.out.print("请输入学生联系方式:");
        String tel = sc.next();

        System.out.print("请输入学生班级:");
        String classid = sc.next();
        return new Student(id, name, sex, age, score, tel, classid);
    }

    public static void showUpdateOutCome(int outcome) {
        if (outcome == 1) {
            System.out.println("修改成功");
        } else {
            System.out.println("修改失败");
        }
    }

    public static void Success(String successMessage) {
        System.out.println(successMessage);
    }
}

